﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using BookManage.BLL;
using BookManage.Model;

namespace BookManage
{
    public partial class frmLogin : Form
    {
        private int loginTimes = 0; //登录次数
        private ReaderAdmin readerBLL = new ReaderAdmin();
        public static Reader reader = null; //登录用户信息，可用于整个程序
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            loginTimes++;
            int rdID;
            rdID = Convert.ToInt32(txtUserID.Text.Trim());
            reader = ReaderAdmin.GetReader(rdID);//读者对象

            if (reader == null)
            {
                txtUserID.Focus();
                lblReaderInfo.Text = "登录信息：查无此人...(" + loginTimes.ToString() + ")";

            }
            else if (loginTimes > 5)
            {
                MessageBox.Show("登录错误超过五次，无法登录，请退出！！！");
                //DateTime current = DateTime.Now;
               /* while (DateTime.Now.Subtract(current).Seconds > 10)
                {
                        MessageBox.Show("请重新登录！！！");
                        Form form = new frmLogin();
                        form.Show();

                }*/

            }
            else 
            {
                if (reader.rdPwd == txtUserPwd.Text)
                {
                    this.DialogResult = DialogResult.OK;//登录成功
                }
                else
                {
                    txtUserPwd.Text = "";
                    txtUserPwd.Focus();
                    lblReaderInfo.Text = "登录信息：密码错误！(" + loginTimes.ToString() + ")";
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {

        }

        private void txtUserID_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnFindPwd_Click(object sender, EventArgs e)
        {
            /*if (txtUserID.Text == "")
                MessageBox.Show("请输入用户名！！！");
            else
            {
                int rdID=Convert.ToInt32(txtUserID.Text);
                reader=ReaderAdmin.GetReader(rdID);
                MessageBox.Show("您的密码为:" + reader.rdPwd);
            }*/
            Form form = new frmFindPwd();
            form.Show();
        }
    }
}
